{%extends "base.html"%}
{%block body%}
<script type="text/javascript">
    YAHOO.namespace("page.semester");

    function init() {
        // Define various event handlers for Dialog
        var handleSubmit = function() {
            this.submit();
        };
        var handleCancel = function() {
            this.cancel();
        };
        var handleSuccess = function(o) {
            window.location="/";
        };
        var handleFailure = function(o) {
            alert("Submission failed: " + o.status);
        };

        // Instantiate the Dialog
        YAHOO.page.semester.dialog1 = new YAHOO.widget.Dialog("dialog1", 
                            { width : "30em",
                              fixedcenter : true,
                              visible : false, 
                              constraintoviewport : true,
                              buttons : [ { text:"Add", handler:handleSubmit, isDefault:true }, { text:"Cancel", handler:handleCancel, isDefault:false } ]
                            });

        // Wire up the success and failure handlers
        YAHOO.page.semester.dialog1.callback = { success: handleSuccess, failure: handleFailure };

        // Render the Dialog
        YAHOO.page.semester.dialog1.render();

        YAHOO.util.Event.addListener("show", "click", YAHOO.page.semester.dialog1.show, YAHOO.page.semester.dialog1, true);
        YAHOO.util.Event.addListener("hide", "click", YAHOO.page.semester.dialog1.hide, YAHOO.page.semester.dialog1, true);
    }

    YAHOO.util.Event.onDOMReady(init);
</script>

<h1>Main Page</h1>
{% if semesters %}
  <table>
    <tr>
      <th>Name</th>
      <th>GPA</th>
      <th>Hours</th>
      <th>Control</th>
    </tr>
  {% for semester in semesters %}
    <tr>
      <td><a href="{%url view.course.listAll semester.key.id%}">{{semester.name}}</a></td>
      <td>
	      {% if semester.gpa %}
	      	{{semester.gpa|floatformat:3}}
	      {% else %}
	      	-
	      {% endif %}
      </td>
      <td>
      {% if semester.semesterHours %}
      	{{semester.semesterHours}}
      {% else %}
      	-
      {% endif %}
      </td>
      <td><a href="{%url view.semester.delete semester.key.id%}">[x]</a></td>
    </tr>
  {% endfor %}
  </table>
{% else %}
  <strong>No semesters entered</strong>
{% endif %}
<button id="show" class="yui-button-focus">Add Semester</button>

<div id="dialog1">
    <div class="hd">
        Enter New Semester
    </div>
    <div class="bd">
        <form action="/addSemester" method="post">
          <table>
          {{semForm}}
          </table>
        </form>
    </div>
</div>

{%endblock%}
